package com.ymatou.iapi.delivery.testcase;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.delivery.parameter.GetBillCodesByOrderIdReq;
import com.ymatou.iapi.delivery.service.GetBillCodesByOrderIdCall;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
/**
*根据订单号查对应的物流单号接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getBillCodesByOrderId {
	private static GetBillCodesByOrderIdReq bean;
	private static GetBillCodesByOrderIdCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据订单号查对应的物流单号接口");
	}

	@Before
	public void caseUp() {
		bean = new GetBillCodesByOrderIdReq();
		call = new GetBillCodesByOrderIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getBillCodesByOrderId_001() {
		Logger.start(true, "根据订单号查询物流信息成功");
		try {

			TradingServiceResp placeOrderResp = TradingPlaceOrderCallService
					.placeOrderWithLogisticsType(LogisticsTypeEnum.OVERSEAS_DELIVERY);
			
			long sellerId = placeOrderResp.getOrderList().get(0).getSellerId();

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();

			long userId = placeOrderResp.getUserId();

			long tradingId = placeOrderResp.getTradingId();
			
			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();
			
			TradingCallService.payOrder(userId, useAccountAmount, tradingId);

			TradingCallService.sellerAcceptOrder(sellerId, orderId);
			TradingSyncService.getSyncResult(orderId);
			TradingCallService.delivery(sellerId, orderId, LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService.getSyncResult(orderId);

			bean.setOrderId(orderId);

			call.setData(bean);
			call.callService();

			Logger.verifyEquals(call.getString("IsSuccess"), "true",
					"校验IsSuccess");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}